package ${classInfo.basePackage}.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ${classInfo.basePackage}.service.${classInfo.className}Service;
import ${classInfo.basePackage}.dataobject.${classInfo.className}DO;

import com.quancheng.common.basic.rest.*;
import com.quancheng.starter.log.LogUtil;
import com.quancheng.starter.log.QcLog;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * ${classInfo.classComment} 控制器
 *
 * Created by code generator on '${.now?string('yyyy-MM-dd HH:mm:ss')}'.
 */
@Api
@RestController
@RequestMapping("/${classInfo.className?uncap_first}")
public class ${classInfo.className}Controller {

    private final static QcLog LOGGER = LogUtil.getLogger(ZeusUserController.class);

    @Resource
    private ${classInfo.className}Service ${classInfo.className?uncap_first}Service;

    /**
     * 新增
     */
    @ApiOperation(value = "新增")
    @PostMapping("/insert")
    public Response<${classInfo.fieldList[0].fieldClass}> insert(@RequestBody ${classInfo.className}DO ${classInfo.className?uncap_first}DO){
        return ${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first}DO);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @GetMapping("/delete/{id}")
    public Response<String> delete(@PathVariable("id") ${classInfo.fieldList[0].fieldClass} id){
        return ${classInfo.className?uncap_first}Service.delete(id) ? Response.success() : Response.error();
    }

    /**
     * 更新
     */
    @ApiOperation(value = "更新")
    @PostMapping("/update")
    public Response<String> update(@RequestBody ${classInfo.className}DO ${classInfo.className?uncap_first}DO){
        return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first}DO) ? Response.success() : Response.error();
    }

    /**
     * 查询
     */
    @ApiOperation(value = "查询")
    @GetMapping("/findById/{id}")
    public Response<${classInfo.className}DO> findById(@PathVariable("id") ${classInfo.fieldList[0].fieldClass} id){
        return Response.success(${classInfo.className?uncap_first}Service.findById(id));
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/pageList")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "1") int page,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        int offset = (page - 1) * pagesize;
        return ${classInfo.className?uncap_first}Service.pageList(offset, pagesize);
    }

    /**
     * 批量插入或修改
     */
    @ApiOperation(value = "批量插入或修改")
    @PostMapping("/saveAll")
    public Response<String> saveAll(@RequestBody List<${classInfo.className}DO> ${classInfo.className?uncap_first}DOs){
        return ${classInfo.className?uncap_first}Service.saveAll(${classInfo.className?uncap_first}DOs);
    }

}
